<template>
  <view :class="['loading-page', loading ? 'show' : 'hide']">
    <view class="loading-wrap">
      <view class="icon">
        <uni-icons type="spinner-cycle" size="40" color="#bbb"></uni-icons>
      </view>
      <slot>
        <text class="text">{{ loadingText }}</text>
      </slot>
    </view>
  </view>
</template>

<script setup>
import { t } from "@/locale/index"
const props = defineProps({
  loadingText: {
    type: String,
    default: t("common.load_ing"),
  },

  loading: {
    type: Boolean,
    default: false,
  },
})
</script>

<style lang="scss" scoped>
.loading-page {
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
  background-color: #fff;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  transition: all .3s ease-in-out;

  &.show {
    opacity: 1;
    visibility: visible;
  }

  &.hide {
    opacity: 0;
    visibility: hidden;
  }
}

.loading-wrap {
  margin-bottom: 100px;
  padding-bottom: calc(150rpx + env(safe-area-inset-bottom));

  .icon {
    margin-bottom: 20rpx;
    display: grid;
    animation: rotate 1s linear infinite;
  }

  .text {
    font-size: 36rpx;
    color: #aaa;
  }
}

@keyframes rotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
</style>
